/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.    
 */
package dk.redillusions.jdbc.proxy.statistics;

/**
 * Class which is able to collect and report statistics for
 * {@link java.sql.Statement}s and {@link java.sql.PreparedStatement}s.
 * 
 * @author Sune Wettersteen
 * 
 */
abstract class AbstractStatementStatistics implements IStatementStatisticsCollector, IStatementStatisticsReporter, IPreparedStatementStatisticsCollector, IPreparedStatementStatisticsReporter {
    /**
     * @see #getBatchQueriesAdded()
     */
    private long batchQueriesAdded = 0;

    /**
     * @see #getBatchQueriesExecuted()
     */
    private long batchQueriesExecuted = 0;

    /**
     * @see #getExecuteInvocations()
     */
    private long executeInvocations = 0;

    /**
     * @see #getExecuteQueryInvocations()
     */
    private long executeQueryInvocations = 0;

    /**
     * @see #getExecuteUpdateInvocations()
     */
    private long executeUpdateInvocations = 0;

    /**
     * {@inheritDoc}
     */
    @Override
    public void increaseBatchQueriesAdded() {
        this.batchQueriesAdded++;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void increaseBatchQueriesExecuted(final long n) {
        this.batchQueriesExecuted++;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void increaseExecuteQueryInvocations() {
        this.executeQueryInvocations++;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void increaseExecuteUpdateInvocations() {
        this.executeUpdateInvocations++;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void increaseExecuteInvocations() {
        this.executeInvocations++;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public long getBatchQueriesAdded() {
        return this.batchQueriesAdded;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public long getBatchQueriesExecuted() {
        return this.batchQueriesExecuted;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public long getExecuteQueryInvocations() {
        return this.executeQueryInvocations;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public long getExecuteUpdateInvocations() {
        return this.executeUpdateInvocations;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public long getExecuteInvocations() {
        return this.executeInvocations;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public long getTotalExecutedQueries() {
        return this.getBatchQueriesExecuted() + this.getExecuteInvocations() + this.getExecuteQueryInvocations() + this.getExecuteUpdateInvocations();
    }

}
